/**
 * @file contests/cf1708/d/main.cpp
 * @brief
 * @see
 * @author Ruiming Guo (guoruiming@stu.scu.edu.cn)
 * @copyright 2022
 * @date 2022/7/17 11:43:44
 **/

#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int a[N];
void solve() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int i = n - 1; i >= 1; --i) {
    int pre = a[i + 1];
    bool ok = false;
    for (int j = i; j >= 1; --j) {
      ok = (a[j] == 0);
      a[j] = pre - a[j];
      pre -= a[j];
      if (ok) {
        sort(a + j, a + i + 1);
        break;
      }
    }
    if (!ok) {
      sort(a + 1, a + i + 1);
    }
  }
  cout << a[1] << '\n';
}
int main() {
  // High rating and good luck!
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int tc;
  cin >> tc;
  while (tc--) {
    solve();
  }
  return 0;
}
